package com.bdqn.qnnews.schedule.convert;

import com.bdqn.qnnews.schedule.api.dto.TaskDto;
import com.bdqn.qnnews.schedule.entity.Taskinfo;
import com.bdqn.qnnews.schedule.entity.TaskinfoLogs;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author xlzhang
 */
@Mapper
public interface TaskConvert {
    /**
     * 转换类实例
     */
    TaskConvert INSTANCE = Mappers.getMapper(TaskConvert.class);

    /**
     * dto 转换为 Taskinfo
     * @param dto dto对象
     * @return 实体对象
     */
    @Mapping(target = "executeTime", ignore = true) // 忽略指定的字段
    @Mapping(target = "taskType",source = "taskTopic")
    Taskinfo dtoToEntity(TaskDto dto);

    /**
     * entity转换dto
     * @param entity 任务实体
     * @return
     */
    @Mapping(target = "executeTime",ignore = true)
    @Mapping(target = "taskTopic",source = "taskType")
    TaskDto entityToDto(Taskinfo entity);

    /**
     * 任务信息转换为任务日志
     * @param taskinfo 任务信息
     * @return 任务信息日志
     */
    TaskinfoLogs infoToInfoLogs(Taskinfo taskinfo);
}